#include <kernel/kernel.h>
#include <lib/stdarg.h>
#include <kernel/screen.h>

#define K "KERNEL"

/*
 * Really simple printf for the kernel
 * Format codes supported: i,s,c
 * No alignment or width can be specified [yet]
 */
int kprintf(const char *fmt, ...)
{
	va_list varargs;
	int i, j, buf_len;
	char buf[64], c;
	char *str;

	if(fmt == NULL)
		return -1;

	va_start(varargs, fmt);

	for(i=0; fmt[i]; i++) {
		if(fmt[i] == '%') {
			i++;
			switch(fmt[i]) {
				case 'i':
					j = va_arg(varargs, int);
					putint(j, 10);
					break;
				case 'X':
					j = va_arg(varargs, int);
					putint(j, 16);
					break;
				case 'c':
					c = va_arg(varargs, char);
					putch(c);
					break;
				case 's':
					str = va_arg(varargs, char *);
					for(; *str; str++)
						putch(*str);
					break;
				default:
					putch('%');
					putch(fmt[i]);
					break;
			}
		}
		else
			putch(fmt[i]);
	}
	
	return 0;
}
